package com.itheima.a04setDemo1;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.function.Consumer;

public class SetDemo1 {
    public static void main(String[] args) {
        Set<String> s = new HashSet<>();

        boolean res1 = s.add("zhangsan");// true
        boolean res2 = s.add("zhangsan");// false

        System.out.println(res1);
        System.out.println(res2);

        s.add("lisi");
        s.add("wangwu");

        System.out.println(s);// [lisi, zhangsan, wangwu]

        // 迭代器遍历
        Iterator<String> it = s.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        // 增强for循环
        for (String s1 : s) {
            System.out.println(s1);
        }

        // Lambda表达式
        s.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        s.forEach(str -> System.out.println(str));
    }
}
